<template>
  <div class="app-container">
    <el-form v-hasPermi="['report:reporting:edit']" :model="queryParams" ref="queryForm" :inline="true"
             v-show="showSearch" label-width="68px">
      <el-form-item label="用户" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入用户"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['report:reporting:add']"
        >上传
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['report:reporting:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['report:reporting:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['report:reporting:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="reportingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="编号" align="center" prop="id"/>
      <el-table-column label="用户" align="center" prop="userName"/>
      <el-table-column label="性别" align="center" prop="gender"/>
      <el-table-column label="年龄" align="center" prop="age"/>
      <el-table-column label="学期" align="center" prop="xueQi"/>
      <el-table-column label="上传时间" align="center" prop="createAt"/>
      <el-table-column label="操作" align="center"
                       class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="func(scope.row)"
          >报表
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['report:reporting:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['report:reporting:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改档案对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1400px" append-to-body>
      <el-form style="display: inline-block" ref="form" :model="form" :rules="rules" label-width="120px">

        <div style="display: inline-block; width: 300px">
          <el-form-item label="学期" prop="xueQi">
            <el-input v-model="form.xueQi" placeholder="格式: 2023年第一学期"/>
          </el-form-item>

          <!--    基础信息    -->
          <el-form-item label="用户" prop="userName">
            <el-input v-model="form.userName" placeholder="请输入用户"/>
          </el-form-item>
          <el-form-item label="性别" prop="gender">
            <el-input v-model="form.gender" placeholder="请输入性别"/>
          </el-form-item>
          <el-form-item label="出生年月" prop="birthday">
            <el-input v-model="form.birthday" placeholder="请输入出生年月"/>
          </el-form-item>
          <el-form-item label="年龄" prop="age">
            <el-input v-model="form.age" placeholder="请输入年龄"/>
          </el-form-item>
          <el-form-item label="监护人姓名" prop="parentName">
            <el-input v-model="form.parentName" placeholder="请输入监护人姓名"/>
          </el-form-item>
          <el-form-item label="监护人身份" prop="sFen">
            <el-input v-model="form.sFen" placeholder="请输入监护人身份"/>
          </el-form-item>
          <el-form-item label="联系方式" prop="telephone">
            <el-input v-model="form.telephone" placeholder="请输入联系方式"/>
          </el-form-item>
          <el-form-item label="既往病史" prop="bingShi">
            <el-input v-model="form.bingShi" type="textarea" placeholder="请输入既往病史"/>
          </el-form-item>

          <!--    五官    -->
          <el-form-item label="视力" prop="shiLi">
            <el-input v-model="form.shiLi" placeholder="左右，以_分割"/>
          </el-form-item>
        </div>

        <div style="display: inline-block; width: 300px">
          <el-form-item label="矫正视力" prop="jZShiLi">
            <el-input v-model="form.jZShiLi" placeholder="左右，以_分割"/>
          </el-form-item>
          <el-form-item label="其他眼疾" prop="yanJi">
            <el-input v-model="form.yanJi" placeholder="请输入其他眼疾"/>
          </el-form-item>
          <el-form-item label="色觉检查" prop="seJueBM">
            <el-input v-model="form.seJueBM" placeholder="请输入彩色图案及编码"/>
          </el-form-item>
          <el-form-item label="色觉检查" prop="seJueSB">
            <el-input v-model="form.seJueSB" placeholder="单色识别:(红,绿,紫,蓝,黄)"/>
          </el-form-item>
          <el-form-item label="嗅觉" prop="xiuJue">
            <el-input v-model="form.xiuJue" placeholder="请输入嗅觉信息"/>
          </el-form-item>
          <el-form-item label="鼻及鼻窦病例" prop="biDou">
            <el-input v-model="form.biDou" type="textarea" placeholder="请输入鼻及鼻窦病例信息"/>
          </el-form-item>
          <el-form-item label="咽喉状况" prop="yanHou">
            <el-input v-model="form.yanHou" type="textarea" placeholder="请输入咽喉状况信息"/>
          </el-form-item>
          <el-form-item label="口吃" prop="kouChi">
            <el-input v-model="form.kouChi" placeholder="请输入口吃信息"/>
          </el-form-item>
        </div>

        <div style="display: inline-block; width: 300px">
          <el-form-item label="口腔" prop="kouQiang">
            <!--     龋齿、缺齿、齿槽 可选     -->
            <el-input v-model="form.kouQiang" placeholder="请输入咽喉状况信息"/>
          </el-form-item>
          <el-form-item label="其他" prop="other">
            <el-input v-model="form.other" type="textarea" placeholder="请输入其他信息"/>
          </el-form-item>

          <!--    外科    -->
          <el-form-item label="身高" prop="sGao">
            <el-input v-model="form.sGao" placeholder="请输入身高（cm）"/>
          </el-form-item>
          <el-form-item label="体重" prop="weight">
            <el-input v-model="form.weight" placeholder="请输入体重（kg）"/>
          </el-form-item>
          <el-form-item label="腰围" prop="yaoWei">
            <el-input v-model="form.yaoWei" placeholder="请输入腰围（cm）"/>
          </el-form-item>
          <el-form-item label="胸围" prop="xWei">
            <el-input v-model="form.xWei" placeholder="请输入胸围（cm）"/>
          </el-form-item>
          <el-form-item label="臀围" prop="tunWei">
            <el-input v-model="form.tunWei" placeholder="请输入臀围（cm）"/>
          </el-form-item>
          <el-form-item label="脊柱" prop="jiZhu">
            <el-input v-model="form.jiZhu" type="textarea" placeholder="请输入脊柱信息"/>
          </el-form-item>
        </div>

        <div style="display: inline-block; width: 300px">
          <el-form-item label="四肢" prop="siZhi">
            <el-input v-model="form.siZhi" placeholder="请输入四肢信息"/>
          </el-form-item>
          <el-form-item label="血压" prop="xueYa">
            <el-input v-model="form.xueYa" placeholder="请输入血压"/>
          </el-form-item>
          <el-form-item label="脉搏" prop="maiBo">
            <el-input v-model="form.maiBo" placeholder="请输入脉搏信息"/>
          </el-form-item>

          <!--    内科    -->
          <el-form-item label="发育营养" prop="faYu">
            <el-input v-model="form.faYu" type="textarea" placeholder="请输入发育营养信息"/>
          </el-form-item>
          <el-form-item label="肺及呼吸道" prop="hxDao">
            <el-input v-model="form.hxDao" type="textarea" placeholder="请输入肺及呼吸道信息"/>
          </el-form-item>
          <el-form-item label="心脏及血管" prop="xinZhang">
            <el-input v-model="form.xinZhang" placeholder="请输入心脏及血管信息"/>
          </el-form-item>
          <el-form-item label="腹部器官:脾" prop="fBuPi">
            <el-input v-model="form.fBuPi" placeholder="请输入信息"/>
          </el-form-item>
          <el-form-item label="腹部器官:肝" prop="fBuGan">
            <el-input v-model="form.fBuGan" placeholder="请输入信息"/>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listReporting, getReporting, delReporting, addReporting, updateReporting} from "@/api/report/reporting";

export default {
  name: "Reporting",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 档案表格数据
      reportingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 学期时间范围
      daterangeReportTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        xueQi: null,
        userName: null,
        gender: null,
        birthday: null,
        age: null,
        parentName: null,
        sFen: null,
        telephone: null,
        bingShi: null,
        shiLi: null,
        jZShiLi: null,
        yanJi: null,
        seJueBM: null,
        seJueSB: null,
        xiuJue: null,
        biDou: null,
        yanHou: null,
        kouChi: null,
        kouQiang: null,
        other: null,
        sGao: null,
        weight: null,
        yaoWei: null,
        xWei: null,
        tunWei: null,
        jiZhu: null,
        siZhi: null,
        xueYa: null,
        maiBo: null,
        faYu: null,
        hxDao: null,
        xinZhang: null,
        fBuPi: null,
        fBuGan: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userName: [
          {required: true, message: "用户不能为空", trigger: "blur"}
        ],
        xueQi: [
          {required: true, message: "学期不能为空", trigger: "blur"}
        ],
        gender: [
          {required: true, message: "性别不能为空", trigger: "blur"}
        ],
        birthday: [
          {required: true, message: "出生年月不能为空", trigger: "blur"}
        ],
        sGao: [
          {required: true, message: "身高不能为空", trigger: "blur"}
        ],
        weight: [
          {required: true, message: "体重不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    func(row) {
      this.$router.push({path: '/world', query: {index: row.id}});
    },
    /** 查询档案列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeReportTime && '' != this.daterangeReportTime) {
        this.queryParams.params["beginReportTime"] = this.daterangeReportTime[0];
        this.queryParams.params["endReportTime"] = this.daterangeReportTime[1];
      }
      listReporting(this.queryParams).then(response => {
        this.reportingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        temperature: null,
        isDizzy: null,
        reportTime: null,
        memo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeReportTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 上传按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加档案";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getReporting(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改档案";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateReporting(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReporting(this.form).then(response => {
              this.$modal.msgSuccess("上传成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除档案编号为"' + ids + '"的数据项？').then(function () {
        return delReporting(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('report/reporting/export', {
        ...this.queryParams
      }, `reporting_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
